﻿using System;
using System.Collections.Generic;
using System.Text;

namespace C11_Ex01_1
{
    public class Program
    {
        public static void Main()
        {
            string inputString;
            int inputNumber = 0;
            int firstNumber = -1;
            int maximalNumber = -1;
            int minimalNumber = -1;
            int sumOfAllNumbers = 0;
            int numberOfInputNumbers = 0;
            int numberOfNumbersDividedByFirstNumber = 0;

            while(inputNumber != -1)
            {
                System.Console.WriteLine("Enter a positive integer number, and then press enter.");
                inputString = System.Console.ReadLine();
                bool parsingSuccess = int.TryParse(inputString, out inputNumber);

                if (!parsingSuccess || (inputNumber <= 0 && inputNumber != -1))
                {
                    System.Console.WriteLine(string.Format("{0} is not a valid input.", inputString));
                }
                else
                {
                    if (inputNumber != -1)
                    {
                        if (firstNumber == -1)
                        {
                            firstNumber = inputNumber;
                        }

                        if (inputNumber > maximalNumber)
                        {
                            maximalNumber = inputNumber;
                        }

                        if (inputNumber < minimalNumber || minimalNumber == -1)
                        {
                            minimalNumber = inputNumber;
                        }

                        sumOfAllNumbers += inputNumber;
                        numberOfInputNumbers++;

                        if (inputNumber % firstNumber == 0)
                        {
                            numberOfNumbersDividedByFirstNumber++;
                        }
                    }
                }
            }

            System.Console.WriteLine(string.Format(
                "Max = {0},{5}Min = {1},{5}Number Of Numbers Entered = {2},{5}Average = {3},{5}Number Of Numbers Divided By First = {4}.",
                maximalNumber,
                minimalNumber,
                numberOfInputNumbers,
                (float)sumOfAllNumbers / numberOfInputNumbers,
                numberOfNumbersDividedByFirstNumber,
                Environment.NewLine));

            System.Console.Write("Press any key to continue . . . ");
            System.Console.ReadLine();
        }
    }
}
